package cn.lyjuan.archetypes.bms.web.exception;

import org.springframework.boot.autoconfigure.web.ErrorViewResolver;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Component
public class AppErrorViewResolver implements ErrorViewResolver
{
    @Override
    public ModelAndView resolveErrorView(HttpServletRequest request, HttpStatus status, Map<String, Object> model)
    {
        switch (status.value())
        {
            case 401: // Unauthorized
                return new ModelAndView("/401");
            case 403: // Forbidden
                return new ModelAndView("/403");
            case 404: // not found
                return new ModelAndView("/400");
            case 500: // Internal Server Error
                return new ModelAndView("/500");
            default:
                return new ModelAndView("/error");
        }
    }
}
